//
//  MTFavoriteViewController.m
//  ShiShiBang
//
//  Created by loujianwei on 16/9/26.
//  Copyright © 2016年 motianjituan. All rights reserved.
//

#import "MTFavoriteViewController.h"
#import "MTFavoriteViewCell.h"
#import "MTFavoriteItem.h"

static NSString * const ID = @"cell";
@interface MTFavoriteViewController ()

/**  */
@property (nonatomic, strong) NSArray *collects;
@end

@implementation MTFavoriteViewController
- (NSArray *)collects {

    if (!_collects) {

        NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"collects.plist" ofType:nil]];

        //字典数组转模型数组
        NSMutableArray *collectArray = [NSMutableArray array];
        for (NSDictionary *dict in dictArray) {
            MTFavoriteItem *collect = [MTFavoriteItem collectWithDict:dict];
            [collectArray addObject:collect];
        }
        _collects = collectArray;
    }
    return _collects;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = themeGrayColor;
    [self initNavigation];
    self.tableView.rowHeight = 150 + 11;
    self.tableView.tableFooterView = [[UIView alloc] init];

}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.collects.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    MTFavoriteViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

    cell.item = self.collects[indexPath.row];

    return cell;
}

#pragma mark -设置导航栏
-(void)initNavigation {
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"back"] highImage:[UIImage imageNamed:@"back anxia"] target:self action:@selector(backClick)];

    self.navigationItem.title = @"我的收藏";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(0x45c75a)]  forBarMetrics:UIBarMetricsDefault];
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
    attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:attr];

    //注册cell
    [self.tableView registerClass:[MTFavoriteViewCell class] forCellReuseIdentifier:ID];
}

- (void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
